package com.xlf.wheretogo.controller;

import com.xlf.wheretogo.entity.Location;
import com.xlf.wheretogo.service.LocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/location")
@Api(value = "LocationController")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @ResponseBody
    @RequestMapping(value = "/getLocation/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据地址ID获取地址信息", notes = "")
    @ApiImplicitParam(paramType = "query", name = "id", value = "地址ID", required = true, dataType = "int")
    public String selectLocationByID(@RequestParam Integer id) {
        Location location=locationService.selectLocationByID(id);
        if (null!=location) {
            return  location.toString();
        }else{
            return "数据不存在";
        }

    }

    @ResponseBody
    @RequestMapping(value = "/deleteLocationByID/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "根据地址ID删除地址信息", notes = "")
    @ApiImplicitParam(paramType = "query", name = "location_id", value = "地址ID", required = true, dataType = "int")
    public String deleteLocationByID(@RequestParam  Integer location_id) {
        if (locationService.deleteLocationByID(location_id) == 1) {
            return "OK";
        } else {
            return "FALSE";
        }
    }

    @ResponseBody
    @RequestMapping(value = "/addLocation/{location}", method = RequestMethod.POST)
    @ApiOperation(value = "添加地址信息", notes = "")
    public String addLocation(@RequestBody Location location){
        if (null == location){
            return "FALSE";
        }
        if (locationService.addLocation(location) == 1) {
            return "OK";
        } else {
            return "FALSE";
        }
    }


}
